﻿using Autofac;
using Blm.VisionCloud.FrameWork.Interceptor.Log;
using VisionCloud.Core;
using VisionCloud.Domain.UnitOfWork;
using VisionCloud.Utility;

namespace VisionSurface.Web.Config
{
    public class IocConfig
    {
        public static void Init(ContainerBuilder builder)
        {
            //builder.RegisterType<JwtTokenAuthorizationHandler>().As<IAuthorizationHandler>().SingleInstance();
            builder.RegisterModelWithInterface("VisionCloud.Domain", w => w.Name.EndsWith("Repository") && !w.IsInterface);
            builder.RegisterModel("VisionSurface.Service", w => w.Name.EndsWith("Service") && !w.Name.Contains("WxApiService"));
            builder.RegisterController("VisionSurface.Web");
            builder.RegisterType<PGUnitOfWork>().As<IUnitOfWork>().PropertiesAutowired().InstancePerLifetimeScope();
            //builder.RegisterType<JwtSecurityTokenHandler>().SingleInstance();
            builder.Register(c => new BlueDbContextFactory().CreateDbContext(new string[] { "1" })).As<BlueDbContext>().PropertiesAutowired().InstancePerLifetimeScope();
            builder.RegisterType<LoggerInterceptor>().PropertiesAutowired().InstancePerLifetimeScope();
            builder.RegisterType<LoggerAsyncInterceptor>().PropertiesAutowired().InstancePerLifetimeScope();
        }
    }
}
